<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <title>{:getStoreName($_GET['local_id'])}-商品列表</title>
    <link rel="stylesheet" href="__PUBLIC__/Home/css/category.css?v=20170317001">
    <include file="Public/common_js"/>
</head>
<body>
<div class="warp">
    <div class="category-goods">
        <!-- 分类菜单 -->
        <div class="sort-bar clearfix">
            <ul>
                <li class="active"><a href="javascript:void(0);">全部</a></li>
                <li><a href="javascript:void(0);">默认排序</a></li>
                <li><a href="javascript:void(0);">筛选</a></li>
            </ul>
            <!-- 弹窗选择 -->
            <div class="full-select full-select-category tips">
                <a category-id='' href="javascript:void(0)">全部</a>
            </div>
            <div class="full-select tips">
                <a sort="1" href="javascript:void(0)">默认排序</a>
                <a sort="2" href="javascript:void(0)">销量</a>
                <a sort="3" href="javascript:void(0)">评价</a>
                <a sort="4" href="javascript:void(0)">价格最高</a>
                <a sort="5" href="javascript:void(0)">价格最低</a>
            </div>
            <div class="filter-select tips">
                <a select="1" href="javascript:void(0)">促销</a>
                <a select="2" href="javascript:void(0)">套餐</a>
            </div>
        </div>
        <!-- 筛选结果 -->
        <div class="filter-goods-list"><ul></ul></div>
        <div class="empty-box" style="display: none;">
            <img src="__PUBLIC__/Home/images/iconEmpty.png" alt="">
            <p>没有找到您要的商品</p>
        </div>
        <!--<div class="item-more">
            {$show}
        </div>-->
    </div>
</div>
<include file="Public/bind_phone"/>
<include file="Public/suspend_cart"/>
<include file="Public/subclass_menu"/>
<script type="text/javascript">
    var _cat_id = "{$cat_id}";
    require(['subClassMain']);
</script>
<script type="text/javascript" src="__PUBLIC__/Home/js/goods/list.js?v=2017020270009"></script>
<script type="text/javascript">
    var cartNumber = $('#unique-cart-number').text();
    var curNumber = '';
    var num = 0;
    var isAjax = false;
    function drag(obj,parentNode){
        var obj = document.getElementById(obj);
        if(arguments.length == 1){
            var parentNode = window.self;
            var pWidth = parentNode.innerWidth,pHeight = parentNode.innerHeight;
        }else{
            var parentNode = document.getElementById(parentNode);
            var pWidth = parentNode.clientWidth,pHeight = parentNode.clientHeight;
        }
        obj.addEventListener('touchstart',function(event){
            //当只有一个手指时              .
            var touch = event.targetTouches[0];
            var disX = touch.clientX - obj.offsetLeft,disY = touch.clientY - obj.offsetTop;
            var oWidth = obj.offsetWidth,oHeight = obj.offsetHeight;

            obj.addEventListener('touchmove',function(event){
                if(event.touches.length == 1){
                    //禁止浏览器默认事
                    event.preventDefault();
                };
                var touch = event.targetTouches[0];
                obj.style.left = touch.clientX - disX  + 'px';
                obj.style.top = touch.clientY - disY + 'px';
                //左侧
                if(obj.offsetLeft <=0){
                    obj.style.left = 0;
                };
                //右侧
                if(obj.offsetLeft >= pWidth -oWidth){
                    obj.style.left =  pWidth - oWidth + 'px';
                };
                //上面
                if(obj.offsetTop <= 0){
                    obj.style.top = 0;
                };
                //下面
                if(obj.offsetTop >= pHeight - oHeight){
                    obj.style.top =  pHeight - oHeight + 'px';
                };
            });
            obj.addEventListener('touchend',function(event){
                //obj.removeEventListener('touchmove');
                //obj.removeEventListener('touchend');
            })
        });
    }

    drag('moveid');
    function addIntoCart(e,_self){
        var _self = $(_self);
        e.preventDefault();
        _global.checkPhoner.verifyfunc = function(rs){
            if(rs){
                addCartAjax(e,_self);
                return true;
            }else{
                return false;
            }
        };
        _global.checkPhoner.succfunc =function(){
            addCartAjax(e,_self);
        };
        _global.checkPhoner.run(e);
    }

    function  addCartAjax(e,_self){
        if(isAjax){
            return false;
        }
        var goodsInfo = {
            sid: _self.data('sid'),
            pid: _self.data('pid'),
            gid: _self.data('gid'),
            spid:_self.data('spid')
        };
        isAjax = true;
        $.ajax({
            url: '/home/carts/addcart'+getFixedExtraUrl(),
            type: 'post',
            data: {
                'pid': goodsInfo.pid,
                'buyNum': 1,
                'goods_id': goodsInfo.gid,
                'local_id': goodsInfo.sid,
                'spid': goodsInfo.spid,
                'action': 'plus'
            },
            dataType: 'json',
            success: function(data) {

                if(data.status == 2) {
                    _global.promote.alertPopup(data.msg);
                }else if(data.status == 0){
                    _global.promote.alertPopup(data.msg);
                    window.location.href=data.url;
                }else{
                    num++;
                    e.preventDefault();
                    curNumber = parseInt(getFixedFloat(cartNumber,num,'+'));
                    _self.addClass('active');
                    _self.find('label').addClass('animate');
                    setTimeout(function(){
                        _self.removeClass('active');
                        _self.find('label').removeClass('animate');
                        $('#unique-cart-number').text(curNumber);
                    },500);
                }
                isAjax = false;
            },
            error: function(err) {
                isAjax = false;
                _global.promote.alertPopup('服务器异常，请稍后重试！')
            }

        });

    }
</script>

</body>
</html>